package com.ivan.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ivan.hospital.mapper.BookingRuleMapper;
import com.ivan.hospital.service.BookingRuleService;
import com.ivan.model.entity.hosp.BookingRule;
import com.ivan.model.vo.hosp.BookingRuleVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/*
 * @Author      Ivan
 * @Date        2023/4/6 8:33
 * @Description BookingRuleServiceImpl
 */
@Service
public class BookingRuleServiceImpl extends ServiceImpl<BookingRuleMapper, BookingRule> implements BookingRuleService {
    /**
     * 添加医院预约规则
     * @param bookingRule
     * @return
     */
    @Override
    public int saveBookingRule(BookingRule bookingRule) {
        return baseMapper.insert(bookingRule);
    }

    /**
     * 条件查询医院预约规则带分页
     * @param current
     * @param limit
     * @param queryVo
     * @return
     */
    @Override
    public Page<BookingRule> findByPage(long current, long limit, BookingRuleVo queryVo) {
        //分页对象
        Page<BookingRule> page = new Page<>(current, limit);
        //查询条件
        QueryWrapper<BookingRule> wrapper = new QueryWrapper<>();
        String hoscode = queryVo.getHoscode();//医院编号
        Integer cycle = queryVo.getCycle();//预约周期
        if (!StringUtils.isEmpty(hoscode)) {
            wrapper.eq("hoscode", queryVo.getHoscode());
        }
        if (!StringUtils.isEmpty(cycle)) {
            wrapper.like("cycle", queryVo.getCycle());
        }
        return baseMapper.selectPage(page, wrapper);
    }

    /**
     * 根据id查询医院预约规则
     * @param id
     * @return
     */
    @Override
    public BookingRule findById(Long id) {
        return baseMapper.selectById(id);
    }

    /**
     * 根据id删除医院预约规则
     * @param id
     * @return
     */
    @Override
    public int removeById(Long id) {
        return baseMapper.deleteById(id);
    }

    /**
     * 根据idList批量删除医院预约规则
     * @param idList
     * @return
     */
    @Override
    public int removeByIds(List<Long> idList) {
        return baseMapper.deleteBatchIds(idList);
    }

    /**
     * 修改医院预约规则
     * @param bookingRule
     * @return
     */
    @Override
    public int updateBookingRule(BookingRule bookingRule) {
        return baseMapper.updateById(bookingRule);
    }
}
